Conditions | 3 |
Paths | 2 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /*jslint |
||
44 | function handleGpxFiles(files) { |
||
45 | 'use strict'; |
||
46 | |||
47 | if (!files || !files.length) { |
||
48 | showAlert( |
||
49 | mytrans("uploadgpx.error"), |
||
50 | mytrans("uploadgpx.error_no_files") |
||
51 | ); |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | var reader = new FileReader(), |
||
56 | parser = new DOMParser(); |
||
57 | |||
58 | reader.readAsText(files[0]); |
||
59 | reader.onloadend = function () { |
||
60 | var xml = parser.parseFromString(reader.result, "text/xml"), |
||
61 | wpts, |
||
62 | wpt, |
||
63 | i; |
||
64 | if (!xml) { |
||
65 | showAlert( |
||
66 | mytrans("uploadgpx.error"), |
||
67 | mytrans("uploadgpx.error_bad_xml") |
||
68 | ); |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | wpts = xml.getElementsByTagName('wpt'); |
||
73 | for (i = 0; i < wpts.length; i = i + 1) { |
||
74 | wpt = parseWpt(wpts[i], 'wpt_' + i); |
||
75 | if (!Markers.newMarker(wpt.coords, -1, wpt.radius, wpt.name)) { |
||
76 | showAlert( |
||
77 | mytrans("uploadgpx.error"), |
||
78 | mytrans("uploadgpx.error_failed_after").replace(/%1/, i) |
||
79 | ); |
||
80 | return; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | showAlert( |
||
85 | mytrans("uploadgpx.info"), |
||
86 | mytrans("uploadgpx.msg_created_markers").replace(/%1/, wpts.length) |
||
87 | ); |
||
88 | |||
89 | // TODO pan to center of imported markers, adjust zoom |
||
90 | }; |
||
91 | |||
92 | // reset file input |
||
93 | $('#buttonUploadGPXinput').wrap('<form>').closest('form').get(0).reset(); |
||
94 | $('#buttonUploadGPXinput').unwrap(); |
||
95 | } |
||
96 |